<?php
require('common_view_functions.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blog 用户后台管理 - 个人设置</title>
<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/mgmt.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
</head>
<body id="bodySettings">
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	<div id="body">
		<div id="side">
			<ul id="settings_cates">
				<li><a href="<?php echo('/' . $blogger_uri . '/mgmt/settings'); ?>" class="curr">基本设置 &raquo;</a></li>
				<li><a href="<?php echo('/' . $blogger_uri . '/mgmt/categories'); ?>">网志分类与 Tag &raquo;</a></li>
				<li><a href="<?php echo('/' . $blogger_uri . '/mgmt/links'); ?>">友情链结 &raquo;</a></li>
			</ul>
		</div>
		<div id="main">
			<div id="settings_basis">
				<h3 class="sectionHeader">基本信息</h3>
				<table id="tblBasicInfo" class="settingsTbl" cellspacing="0">
					<tr>
						<td class="label">用户名：</td>
						<td><?php echo(htmlspec($blog_info->user_name)); ?> | <?php echo('/' . (is_null($blog_info->user_url) ? '未设置' : $blog_info->user_url)); ?> | <input type="button" id="btnChPwd" class="button" value="修改密码" /></td>
					</tr>
					<tr>
						<td class="label">E-mail：</td>
						<td><span id="emailHolder"><?php echo(($blog_info->email == '') ? '未设置' : htmlspec($blog_info->email)); ?></span> | <input type="button" id="btnChEmail" class="button" value="修改 E-mail" /></td>
					</tr>
					<tr>
						<td class="label">头像：</td>
						<td><a href="javascript:;" id="lnkChAvatar"><img id="imgUserAvatar" class="avt" alt="" border="0" src="<?php echo(base_url() . 'img/avatars/' . $avatar_filename); ?>" /></a> <span class="hint">要更换，请点击图片</span></td>
					</tr>
				</table>
				<h3 class="sectionHeader">Blog 设置</h3>
				<table id="tblBlogSettings" class="settingsTbl" cellpadding="0">
					<tr>
						<td class="label">Blog 名称：</td>
						<td><input type="text" id="txtBlogTitle" name="txtBlogTitle" class="textBox" size="16" maxlength="64" style="width:16em;" value="<?php echo(htmlspec($blog_info->title)); ?>" /></td>
					</tr>
					<tr>
						<td class="label">Blog 宣言：</td>
						<td><input type="text" id="txtBlogSlogan" name="txtBlogSlogan" class="textBox" size="16" maxlength="128" style="width:16em;" value="<?php echo(htmlspec($blog_info->slogan)); ?>" /></td>
					</tr>
					<tr>
						<td class="label">首页公告：</td>
						<td><textarea id="txtAnn" name="txtAnn" class="textBox" cols="32" rows="12" style="width:32em;"><?php echo(htmlspec($blog_info->announcement)); ?></textarea></td>
					</tr>
					<tr>
						<td class="label">好友密码：</td>
						<td><input type="text" id="txtFrPwd" name="txtFrPwd" class="textBox" size="12" maxlength="32" style="width:12em;" value="<?php echo(htmlspec($blog_info->friend_password)); ?>" /> <span class="hint">供他人查看保密网志用</span></td>
					</tr>
					<tr>
						<td class="label">界面主题：</td>
						<td>
<!-- BLOG-SKINS -->
							<select id="selThemes" name="selThemes" class="textBox">
								<option value="Default"<?php if($blog_info->skin_name == 'Default') { echo(' selected="selected"'); } ?>>默认 [ NeoBlue ]</option>
								<option value="AyayaSnow"<?php if($blog_info->skin_name == 'AyayaSnow') { echo(' selected="selected"'); } ?>>Ayaya-Snow [ 冬 ]</option>
								<option value="Clover"<?php if($blog_info->skin_name == 'Clover') { echo(' selected="selected"'); } ?>>三叶草 [ 绿色主题 ]</option>
								<option value="QuietSummer"<?php if($blog_info->skin_name == 'QuietSummer') { echo(' selected="selected"'); } ?>>宁静的夏天 ［ 夏 ］</option>
								<option value="VisualBlue"<?php if($blog_info->skin_name == 'VisualBlue') { echo(' selected="selected"'); } ?>>视觉淡蓝 ［ 支持 800x600 ］</option>
								
								<option value="Freedom"<?php if($blog_info->skin_name == 'Freedom') { echo(' selected="selected"'); } ?>>Freedom [ Birds in Cage ]</option>
								<option value="Mono"<?php if($blog_info->skin_name == 'Mono') { echo(' selected="selected"'); } ?>>Mono [ 黑白极简主义 ]</option>
								<option value="Suu"<?php if($blog_info->skin_name == 'Suu') { echo(' selected="selected"'); } ?>>Suu [ 萌主题 ]</option>
							</select>
<!-- /BLOG-SKINS -->
							<img id="imgSkinPreview" style="border:1px solid #000;width:80px;height:30px;vertical-align:middle;" alt="" />
						</td>
					</tr>
					<tr>
						<td class="label">界面语种：</td>
						<td>
							<select id="selLang" name="selLang" class="textBox">
								<option value="Chinese" selected="selected">简体中文 / Simp. Chinese</option>
								<!--
								<option value="English">English</option>
								<option value="German">Deutsch / German</option>-->
							</select>
						</td>
					</tr>
					<tr>
						<td class="label">开放程度：</td>
						<td><input type="checkbox" id="chkAllowPubCmt" value="nein"<?php if(!$blog_info->allow_public_comment) { ?> checked="checked"<?php } ?> /> <label for="chkAllowPubCmt">社区以外用户的评论需要经我审核</label></td>
					</tr>
					<tr>
						<td colspan="2" style="text-align:right;"><input type="button" id="btnSaveChanges" class="button" value=" 保存个人设置 " /></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="z"></div>
	</div>
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
</div>
<div id="chPwdDiv" class="jqmWindow popout">
	<dl>
		<dt>修改登录密码</dt>
		<dd>
			<label for="txtNewPwd">新密码：</label>
			<input type="password" id="txtNewPwd" maxlength="32" class="textBox" size="12" style="width:12em;" />
			<label for="txtNewPwdRep">重复输一遍：</label>
			<input type="password" id="txtNewPwdRep" maxlength="32" class="textBox" size="12" style="width:12em;" />
			<input type="button" id="btnDoChPwd" class="button" value="确定" />
			<input type="button" id="btnCancelChPwd" class="button" value="取消" />
		</dd>
	</dl>
</div>
<div id="chEmailDiv" class="jqmWindow popout">
	<dl>
		<dt>修改 E-mail</dt>
		<dd>
			<label for="txtNewEmail">新 E-mail：</label>
			<input type="text" id="txtNewEmail" class="textBox" size="16" maxlength="64" style="width:16em;" />
			<input type="button" id="btnDoChEmail" class="button" value="确定" />
			<input type="button" id="btnCancelChEmail" class="button" value="取消" />
		</dd>
	</dl>
</div>
<div id="fileUploadDiv" class="jqmWindow popout">
	<form id="frmFileUpload">
		<dl>
			<dt>更改头像图片</dt>
			<dd>上传一张新头像。最佳尺寸 96x96 像素，<span style="color:red;">仅限 <strong>JPG</strong> 格式</span>。</dd>
			<dd id="uploadingNotify">正在上传，请稍等...</dd>
			<dd>
				<input type="file" id="filAvtUpload" name="filAvtUpload" class="textBox" size="16" />
				<input type="button" id="btnAvtUpload" class="button" value="上传" />
				<input type="button" id="btnCancelUpload" class="button" value="取消" />
			</dd>
		</dl>
	</form>
</div>

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/ajaxfileupload.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";

var blogSettings = {
	"title": "",
	"slogan": "",
	"announcement": "",
	"friendPassword": "",
	"theme": "Default",
	"language": "Chinese",
	"allowPublicComment": true
};

function chPwdCallback(rdata) {
	$("#ajaxLoading").hide();
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	$("#chPwdDiv").jqmHide();
	$("#txtNewPwd").val("");
	$("#txtNewPwdRep").val("");
	alert("用户密码已经更改。");
}

var newEmail = "";
function chEmailCallback(rdata) {
	$("#ajaxLoading").hide();
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	$("#chEmailDiv").jqmHide();
	$("#txtNewEmail").val("");
	$("#emailHolder").html(newEmail);
	alert("用户 E-mail 已经更改。");
}

function updateBlogInfoCallback(rdata) {
	$("#ajaxLoading").hide();
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	}
	alert("Blog 设置已经更改。");
}

$(document).ready(function() {
	$("#chPwdDiv").jqm();
	$("#chEmailDiv").jqm();
	$("#fileUploadDiv").jqm();
	
	$("#btnChPwd").click(function() {
		$("#chPwdDiv").jqmShow();
	});
	
	$("#btnChEmail").click(function() {
		$("#chEmailDiv").jqmShow();
	});
	
	$("#lnkChAvatar").click(function() {
		$("#fileUploadDiv").jqmShow();
	});
	
	$("#btnAvtUpload").click(function() {
		return ajaxFileUpload();
	});
	
	$("#btnCancelUpload").click(function() {
		$("#fileUploadDiv").jqmHide();
	});
	
	$("#btnCancelChPwd").click(function() {
		$("#chPwdDiv").jqmHide();
	});
	
	$("#btnCancelChEmail").click(function() {
		$("#chEmailDiv").jqmHide();
	});
	
	$("#selThemes").change(function() {
		var themeName = $("#selThemes").val();
		var imageSrc = "/img/themes/" + themeName + "/" + themeName + "_Preview.jpg";
		$("#imgSkinPreview").attr("src", imageSrc);
	});
	
	$("#btnSaveChanges").click(function() {
		var blogTitle = $("#txtBlogTitle").val();
		if(blogTitle == "") {
			alert("Blog 名称不能为空！");
			return;
		}
		var blogSlogan = $("#txtBlogSlogan").val();
		var blogAnn = $("#txtAnn").val();
		var blogFrPwd = $("#txtFrPwd").val();
		if(blogFrPwd == "") {
			alert("好友密码不能为空！");
			return;
		}
		var blogTheme = $("#selThemes").val();
		var blogLang = $("#selLang").val();
		var oChkAllowPubCmt = $("#chkAllowPubCmt:checked");
		var blogAllowPubCmt = true;
		if(oChkAllowPubCmt.val() == "nein") {
			blogAllowPubCmt = false;
		}
		
		blogSettings.title = blogTitle;
		blogSettings.slogan = blogSlogan;
		blogSettings.announcement = blogAnn;
		blogSettings.friendPassword = blogFrPwd;
		blogSettings.theme = blogTheme;
		blogSettings.language = blogLang;
		blogSettings.allowPublicComment = blogAllowPubCmt;
		
		$("#ajaxLoading").show();
		$.post(g_userSiteRoot + "/mgmt/settings", {
			"hidIsPostBack": "ja",
			"posted_data": JSON.stringify(blogSettings)
		}, updateBlogInfoCallback);
	});
	
	// change pwd
	$("#btnDoChPwd").click(function() {
		var newPwd = $("#txtNewPwd").val();
		var newPwdRep = $("#txtNewPwdRep").val();
		if(newPwd == "") {
			alert("密码不能为空！");
			return;
		}
		if(newPwd != newPwdRep) {
			alert("确认密码与原密码不一致！");
			return;
		}
		// do change pwd
		$("#ajaxLoading").show();
		$.post(g_userSiteRoot + "/mgmt/change_password_email", {
			"hidIsPostBack": "ja",
			"operation": "ch_password",
			"new_password": newPwd
		}, chPwdCallback);
	});
	
	// change email
	$("#btnDoChEmail").click(function() {
		newEmail = $("#txtNewEmail").val();
		// do change email
		$("#ajaxLoading").show();
		$.post(g_userSiteRoot + "/mgmt/change_password_email", {
			"hidIsPostBack": "ja",
			"operation": "ch_email",
			"new_email": newEmail
		}, chEmailCallback);
	});

	// Skin-Preview image 1st show
	var themeName1 = $("#selThemes").val();
	var imageSrc1 = "/img/themes/" + themeName1 + "/" + themeName1 + "_Preview.jpg";
	$("#imgSkinPreview").attr("src", imageSrc1);

});

function ajaxFileUpload() {
	$("#uploadingNotify").ajaxStart(function() {
		$("#ajaxLoading").show();
		$(this).show();
	}).ajaxComplete(function() {
		$(this).hide("slow", function() {
			$("#ajaxLoading").hide();
			$("#fileUploadDiv").jqmHide();			
		});
	});

	$.ajaxFileUpload({
		"url": g_userSiteRoot + "/mgmt/upload_avatar",
		"secureuri": false,
		"fileElementId": "filAvtUpload",
		"dataType": "json",
		"success": function(data, status) {
			if(typeof(data.error) != "undefined") {
				if(data.error != "") {
					alert("Error: " + data.error);
				} else {
					$("#uploadingNotify").html("<span style=\"color:green;\">上传完成。</span>");
					$("#imgUserAvatar").attr("src", "/img/avatars/" + data.avatar + "?R=" + Math.random());
				}
			}
		},
		"error": function(data, status, e) {
			alert("Oops... " + e);
		}
	});
	
	return false;
}
// -->
</script>
<!-- /JS -->

<div id="ajaxLoading"><img alt="Loading..." src="/img/ajax_loading.gif" border="0" width="24" height="24" /></div>
</body>
</html>